﻿<%@ Page Language="C#" Title="路面性能模型" MasterPageFile="~/W_View/PageMaster.Master" CodeBehind="Dm_Origpv_RegPage.aspx.cs" Inherits="STHPMS1.Web.W_View.Decision.Dm_Origpv_RegPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    
    <%= UiHelper.RefJsFileHtml("/Scripts/Highcharts/highcharts.js")%> 
    
    <script type="text/javascript">   
        function addPanel()
        {
            $('#fm').form('clear');
            $('#Modelid').textbox('readonly', false);
            $('#dlg').dialog('open');
        }

        function editPanel() {
            var model = _selectModel;
            if (!model) {
                $.messager.alert('消息提示', '编辑数据时，请选择一个路面性能模型!', 'warning');
                return;
            }
            $('#Modelid').textbox('readonly', true);

            var rect = {};
            rect.value = model.Modeltype;
            reqSeg(rect, function () {
                $('#fm').form('load', model);
                $('#dlg').dialog('open');
            });
        }       

        function delPanel() {
            var model = _selectModel
            if (!model) {
                $.messager.alert('消息提示', '编辑数据时，请选择一个路面性能模型!', 'warning');
                return;
            }

            $.ajax({
                type: "Delete",
                url: "/api/origpv_reg",
                data: model,
                success: function () {
                    $('#dlg').dialog('close');
                    $('#cmbModels').combobox('reload');
                    _selectModel = null;
                    $.messager.alert('提示', "删除成功!");
                },
                error: function (err) {
                    $.messager.alert('错误提示', err.responseJSON.ExceptionMessage, "error");
                }
            });
        }

        function sumbitData1() {
            //当选择直线型、指数型时，年份跨度≥1；当选择S型、多项式时，年份跨度≥2:
            var modeltype = $("#Modeltype").combobox("getValue");
            if (modeltype == 751)
            {
                var beginYear = $("#beginYear").combobox("getValue");
                var endYear = $("#endYear").combobox("getValue");
                if(!beginYear || !endYear)
                {
                    $.messager.alert('错误提示', '必须输入回归年份 !', "error");
                    return;
                }
                var tff=endYear-beginYear;
                var model = $("#Modelmode").combobox("getValue");
                if ((model == 821 || model == 822 )&& tff < 1)
                {
                    $.messager.alert('错误提示', '直线型、指数型时，年份跨度≥1!', "error");
                    return;
                }
                if ((model == 823 || model == 824) && tff < 2) {
                    $.messager.alert('错误提示', '当选择S型、多项式时，年份跨度≥2!', "error");
                    return;
                }
            }

            $.messager.progress({
                title: '请等待',
                msg: '加载数据中...'
            });

            $("form").ajaxSubmit({
                complete: function () {
                    $.messager.progress('close');
                },
                success: function (responseText) {
                    $('#dlg').dialog('close');
                    $('#cmbModels').combobox('reload');
                },
                error: function (err) {
                    $.messager.alert('错误提示', err.responseJSON.ExceptionMessage, "error");
                }
            });
        }

        var _selectModel;
        function reqSeg(rect,callback) {
            var group_url = '';
            if (rect.value == 752)//养护后
            {
                group_url = '/api/origpv_reg/group';
                $('#Regbeginyear').hide();
            }
            else {
                group_url = '/api/oripv_anagroup/group';
                $('#Regbeginyear').show();
            }

            $.ajax({
                url: group_url,
                type: 'get',
                success: function (data1) {
                    $('#Ansgroup_Id').combobox('loadData', data1).combobox('clear');
                    if (callback) callback();
                },
                error: function (err) {
                    $.messager.alert('错误提示', '获取模型组数据失败 -' + err, 'error');
                }
            });
        }

        function queryModel(n, o) {
            var model = $('#cmbModels').combobox("getValue");
            var modeUrl = '/api/origpv_reg';
            var urlParam = "";
            if (model != "" && model != "0") urlParam += "model=" + encodeURI(model) + "&";
            if (urlParam != "") {
                urlParam = "?" + urlParam.substring(0, urlParam.length - 1);
                modeUrl = modeUrl + urlParam;
            }


            $.ajax({
                type: 'get',
                async: false,
                url: modeUrl,
                dataType: "json",
                success: function (msg) {
                    if (msg) {
                        _selectModel = msg.model;
                        $('#container').highcharts(msg);
                    }
                },
                error: function (err) {
                    $.messager.alert('错误提示', err.responseJSON.ExceptionMessage, 'error');
                }
            });
        }

        $(function () {
            var rect = {};
            rect.value = 751;
            reqSeg(rect);
        })
    </script>    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <h2>路面性能模型</h2>
	<div style="margin:20px 0 10px 0;">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="addPanel()">添加</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="delPanel()">删除</a>
         <select id="cmbModels" class="easyui-combobox" style="width:300px" data-options="prompt:'路面性能模型',
                                                                                                             url:'/api/origpv_reg/models',method:'get',
                                                                                                             valueField:'Modelid',
                                                                                                             textField:'Modelid',
                                                                                                             groupField:'ModelGroup',
                                                                                                             onChange:queryModel">
        </select>
	</div>

    <!--保存框-->
     <div id="dlg" class="easyui-dialog" title="保存数据" style="width:360px;height:260px;padding:10px" closed="true"  data-options="
				iconCls: 'icon-save',
				buttons: '#dlg-buttons'
			">
        <form id="fm" method="post" action="/api/origpv_reg">
            <table>
                <tr>
                    <td>模型名称:</td>
                    <td><input id="Modelid" name='Modelid' class='easyui-validatebox easyui-textbox' data-options="required:true,validType:'MaxLength[50]'" /></td>
                </tr>
                 <tr>
                    <td>模型类型:</td>
                    <td><select class="easyui-combobox" name="Modeltype" id="Modeltype" style="width:170px;" data-options="onSelect:reqSeg ">
		                <option value="751">原路面</option>
		                <option value="752">养护后</option>
	                    </select></td>
                </tr>
                <tr>
                    <td>分析组:</td>        
                    <td><input id="Ansgroup_Id" name='Ansgroup_Id'  class="easyui-validatebox  easyui-combobox" data-options="prompt:'分析组',required:true,valueField:'Ansgroup_Id',textField:'Ansgroup_Id',method:'get' "/></td>
                </tr>
                <tr>
                    <td>回归指标:</td>
                    <td><select class="easyui-combobox" name="Regre_Index" style="width:170px;">
		                    <option value="801">PQI</option>
		                    <option value="802">PCI</option>
                            <option value="803">PSSI</option>
		                    <option value="804">RQI</option>
                            <option value="805">RDI</option>
		                    <option value="806">SRI</option>
	                    </select></td>
                </tr>
                <tr>
                    <td>模型形式:</td>
                     <td><select class="easyui-combobox" name="Modelmode" id="Modelmode" style="width:170px;">
		                    <option value="821">直线型</option>
		                    <option value="823">多项式型</option>
	                    </select>
                     </td>
                </tr>    
                <tr id="Regbeginyear">
                    <td>回归年份:</td>
                    <td><input id="beginYear" name='Regbeginyear' class="easyui-combobox" data-options="prompt:'年份',valueField:'id',textField:'id' ,method:'get',url:'/api/data/years' " style="width:80px;"/>-
                        <input id="endYear" name='Regendyear' class="easyui-combobox" data-options="prompt:'年份',valueField:'id',textField:'id' ,method:'get',url:'/api/data/years' " style="width:80px;"/>
                    </td>
                </tr>
		    </table>
        </form>
    </div>
    <!--编辑数据命令-->
    <div id="dlg-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:sumbitData1()">保存</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#dlg').dialog('close')">取消</a>
	</div>

    
	<div id="aa" class="easyui-accordion" style="width:auto;height:auto;">
        <div title="查看模型" data-options="iconCls:'icon-ok'" style="overflow:auto;padding:10px;">
			<div id="container" style=" margin: 0 auto" />
		</div>
	</div>
</asp:Content>
